#!usr/bin/env python
# -*- coding:utf-8 -*-
"""
@author: lenovo by XYF
@file: crawl.py
@time: 2020/02/20
@function:
"""
# import requests
# import os
# import time
# import re
# from lib.amidoufu import Amidoufu
# from selenium import webdriver

from amidoufu import Amidoufu


# driver = webdriver.Chrome()
# driver.get("https://live.kuaishou.com/v/hot/")
# name = driver.find_element_by_xpath('//*[@id="app"]/div[1]/div[1]/header/div/div[2]/div[3]/a/span')
# name_title = name.get_attribute('title')
# # cookie= driver.get_cookies()
# while name_title == "":
#     print("你还没有登录,请登录!!!")
#     time.sleep(10)
#     name = driver.find_element_by_xpath('//*[@id="app"]/div[1]/div[1]/header/div/div[2]/div[3]/a/span')
#     name_title = name.get_attribute('title')
# # 打印cookie信息
# print("你已经登录,登录名:" + name_title)
# cookie = driver.get_cookies()
# driver.get("https://live.kuaishou.com/u/G338217245/3xjz7rnjnh6hjts")
# cookie = [item['value'] for item in driver.get_cookies()]
# # cookie = [item['name'] + '=' + item['value'] for item in driver.get_cookies()]
# print(cookie)
# param_did = cookie[4]
# # param_kuaishou.live.web_st = cookie[1]
# driver.get("https://live.kuaishou.com/v/hot/")
# #param_did = "123"

# __headers_Requests_web = {
#         'accept': '*/*',
#         'Accept-Encoding': 'gzip, deflate, br',
#         'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
#         'Connection': 'keep-alive',
#         'Host': 'v.kuaishou.com',
#         'Upgrade-Insecure-Requests': '1',
#         # User-Agent/Cookie 根据自己的电脑修改
#         'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
#         'Cookie': ''
#     }

# url = 'https://v.kuaishou.com/94yfzk'
# r = requests.get(url,headers=__headers_Requests_web)
# reditList = r.history#可以看出获取的是一个地址序列
# #print(f'获取重定向的历史记录：{reditList}')
# #print(f'获取第一次重定向的headers头部信息：{reditList[0].headers}')
# print(f'获取重定向最终的url：{reditList[len(reditList)-1].headers["location"]}')



# #    url = 'https://c.m.chenzhongtech.com/rest/lapi/getcoo?_='+str(int(round(time.time() * 1000)))
# url = 'https://live.kuaishou.com/u/G338217245/3xjz7rnjnh6hjts'
# headers_web = {
#     'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
#     'Accept-Encoding': 'gzip, deflate, br',
#     'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
#     'Connection': 'keep-alive',
#     'Host': 'live.kuaishou.com',
#     #    'Origin': 'https://v.kuaishou.com',
#     #    'Referer': 'https://v.kuaishou.com/fw/photo/3xqbgg5rrpui69c',
#     'Sec-Fetch-Dest': 'document',
#     'Sec-Fetch-Mode': 'navigate',
#     'Sec-Fetch-Site': 'none',
#     'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36',
#     #    'Cookie':'did=web_c78c7a3f39befb6076e5891268254f0f'
# }
# rs = requests.get(url=url, headers=headers_web, allow_redirects=False)
# #    resJson = json.loads(rs.content.decode(encoding='utf-8'))
# global cookies
# #    cookies = resJson['cookies'][0].split(';')[0]
# param_did = rs.cookies._cookies['.kuaishou.com']['/']['did'].value


def doudou():
    amidoufu = Amidoufu(False)
    #crawler.set_did(param_did)
    amidoufu.doufu()


if __name__ == "__main__":
    doudou()
